import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { AuthService } from '../../../../core/services/auth.service';

@Component({
  selector: 'app-login-form',
  templateUrl: './loginForm.component.html',
  styleUrls: ['./loginForm.component.scss']
})
export class LoginFormComponent implements OnInit {
  loginInfo: FormGroup;

  constructor(
    private auth: AuthService,
    private formBuilder: FormBuilder
  ) { }

  ngOnInit() {
    this.createForm();
  }

  createForm() {
    this.loginInfo = this.formBuilder.group({
      userName: '',
      pwd: ''
    });
  }

  login() {
    this.auth.login(this.loginInfo.get('userName').value, this.loginInfo.get('pwd').value).subscribe(x => {
      this.auth.redirectAfterLogin();
    });
  }

}
